﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Young3.FMSearch.Core.Entities.GameVersions;
using Young3.FMSearch.Core.Managers;
using Young3.FMSearch.Core.Offsets;
using Young3.FMSearch.Core.Attributes;

namespace Young3.FMSearch.Core.Entities.InGame
{
    //[FMType(UseCache = false)]
    public class Contract : BaseObject
    {
        public Contract(int memoryAddress, IVersion version) : base(memoryAddress, version) { }
                public Contract(int memoryAddress, ArraySegment<byte> originalBytes, IVersion version)
            : base(memoryAddress, originalBytes, version)
        { }

        [FMPointer(ContractOffsets.ClubPointer)]
        public Club Club { get; internal set; }

        [FMEntityAttribute(ContractOffsets.AppearanceBonus)]
        public Int32 AppearanceBonus { get; set; }

        [FMEntityAttribute(ContractOffsets.ClubPointer)]
        private int ClubPointer { get; set; }

        [FMEntityAttribute(ContractOffsets.ContractExpiresDays)]
        public DateTime ContractExpiryDate { get; set; }

        [FMEntityAttribute(ContractOffsets.ContractStarted)]
        public DateTime ContractStarted { get; set; }

        [FMEntityAttribute(ContractOffsets.GoalBonus)]
        public Int32 GoalBonus { get; set; }

        [FMEntityAttribute(ContractOffsets.CleanSheetBonus)]
        public Int32 CleanSheetBonus { get; set; }

        [FMEntityAttribute(ContractOffsets.JobType)]
        public byte JobType { get; set; }

        [FMEntityAttribute(ContractOffsets.Wages)]
        public int WagePerWeek { get; set; }

        [FMEntityAttribute(ContractOffsets.Happiness)]
        public byte Happiness { get; set; }

        [FMEntityAttribute(ContractOffsets.SquadNumber)]
        public byte SquadNumber { get; set; }

        [FMEntity(ContractOffsets.AgreedPrice)]
        public Int32 AgreedPrice { get; set; }

        [FMEntity(ContractOffsets.ContractType)]
        internal Byte _ContractType { get; set; }
        public ContractType ContractType
        {
            get { return (ContractType)_ContractType; }
            set { _ContractType = (Byte)value; }
        }

        public ContractTypeSecond ContractTypeSecond
        {
            get { return (ContractTypeSecond)_ContractType; }
            set { _ContractType = (Byte)value; }
        }

        [FMEntity(ContractOffsets.TeamStatus)]
        internal Byte _TeamStatus { get; set; }
        public TeamStatus TeamStatus
        {
            get { return (TeamStatus)_TeamStatus; }
            set { _TeamStatus = (Byte)value; }
        }

        [FMEntity(ContractOffsets.TransferStatus)]
        internal Byte _TransferStatus { get; set; }
        public TransferStatus TransferStatus
        {
            get { return (TransferStatus)_TransferStatus; }
            set { _TransferStatus = (Byte)value; }
        }
    }


    /*
     * Contracts for directors etc. may have been removed.
     * Club jobs values below. National jobs are different.
     * 02 - 0000 0010   Coach
     * 12 - 0000 1100   Physio
     * 14 - 0000 1110   Scout
     * 16 - 0001 0000   Manager
     * 20 - 0001 0100   Ast Man
     * 26 - 0001 1010   Fitness coach
     * 34 - 0010 0010   Gk coach
     * 48 - 0011 0000   Youth coach
     * 54 - 0011 0110   1st Team coach
     */

    public enum TeamStatus
    {
        Backup = 4,
        DecentYoung = 6,
        FirstTeam = 2,
        HotProspect = 5,
        Indispensable = 1,
        NotNeeded = 7,
        Null = -1,
        SquadRotation = 3
    }

    public enum ContractStatus
    {
        Loan = 0,
        Coowned = 1,
        PartTime = 0,
        FullTime = 1,
        Amateur = 2,
        Youth = 3,
        Non = 6
    }

    // applies on first contract
    public enum ContractType
    {
        PartTime = 0,
        FullTime = 1,
        Amateur = 2,
        Youth = 3,
        Non = 6
    }

    // applies on second contract
    public enum ContractTypeSecond
    {
        Loan = 0,
        Coowned = 1
    }

    public enum TransferStatus
    {
        Loan = 2,
        LoanNone = 0,
        LoanNotFor = 0x40,
        TransByRequ = 8,
        TransListed = 1,
        TransNone = 4,
        TransNotForSale = 0x10
    }
}